<template>
  <div class="Page Confirm">
    <div class="Title">
      <h1 class="fl f18">订单确认</h1>
      <img src="~/assets/img/cart_setp2.png" class="fr" />
      <div class="clear"></div>
    </div>
    <form name="flowForm" id="flowForm" method="post" action="">
      <table class="GoodList">
        <tbody>
          <tr>
            <th class="name">产品</th>
            <th class="price">创建时间</th>
            <th class="priceNew">价格</th>
          </tr>
        </tbody>
        <tbody>
          <tr class="good">
            <td class="name First">
              <a target="_blank" :href="productInfo.img">
                <img :src="productInfo.img"
              /></a>
              <div class="goodInfo">
                <input type="hidden" class="ids ids_14502" value="14502" />
                <a target="_blank" href="#">{{ productInfo.name }}</a>
              </div>
            </td>

            <td class="price">
              <p>
                <strong>{{ productInfo.createTime }}</strong>
              </p>
            </td>
            <td class="red priceNew Last">
              ￥<strong>{{ productInfo.price }}</strong>
            </td>
          </tr>
          <tr>
            <td class="Billing tr" colspan="3">
              <div class="tr">
                <p>
                  共 <strong class="red">1</strong> 件商品，合计<span
                    class="red f20"
                    >￥<strong>{{ productInfo.price }}</strong></span
                  >
                </p>
              </div>
            </td>
          </tr>
        </tbody>
      </table>
  <el-alert
    title="警告"
    type="warning"
    description="请在创建订单15分钟内支付，否则将会过期"
    show-icon>
  </el-alert>
      <div class="Finish">
        <div class="fr" id="AgreeDiv">
          <label for="Agree"
            ><p class="on">
              <input type="checkbox" checked="checked" />我已阅读并同意<a
                href="javascript:"
                target="_blank"
                >《三湘银行购买协议》</a
              >
            </p></label
          >
        </div>
        <div class="clear"></div>
        <div class="Main fl">
          <div class="fl">
            <a href="#">返回产品详情页</a>
          </div>
          <div class="fr">
            <p>
              共 <strong class="red">1</strong> 件商品，合计<span
                class="red f20"
                >￥<strong id="AllPrice">{{ productInfo.price }}</strong></span
              >
            </p>
          </div>
        </div>
        <input name="score" value="0" type="hidden" id="usedScore" />
        <button
          class="fr redb"
          type="button"
          id="submitPay"
          @click="toPay(productInfo.price, productInfo.orderId)"
        >
          去支付
        </button>
        <div class="clear"></div>
      </div>
    </form>
  </div>
</template>
<script>
import orderApi from "@/api/Order";
import payApi from "@/api/pay";
export default {
  data() {
    return {
      productInfo: {},
      countDown:"",
    };
  },
  //根据订单id获取订单信息
  created() {
    //return orderApi.querySeckillProductById()
  },
  methods: {
    //点击去支付，跳转到支付页面
    toPay(price, id) {
      var orderId = this.getQueryString("orderId");
      var productId = this.getQueryString("productId");
      this.$alert("是否支付" + price + "元？", "支付", {
        confirmButtonText: "确定",
        callback: (action) => {
          orderApi.payNormalOrder(orderId, productId).then((response) => {
            console.log(response);
            if (response.data.code == 200) {
              this.$message({
                message: "恭喜你，支付成功",
                type: "success",
              });
this.$router.push({path: '/'})
            } else {
              this.$message.error(response.data.message);
            }
          });
        },
      });
    },

   sleep(n) {
        var start = new Date().getTime();
        //  console.log('休眠前：' + start);
        while (true) {
            if (new Date().getTime() - start > n) {
                break;
            }
        }
        // console.log('休眠后：' + new Date().getTime());
        this.$router.push({path: '/'})
    },
    is_login() {
      this.logout();
      this.$confirm("你的身份已过期,请重新登录", "提示", {
        confirmButtonText: "去登录",
        cancelButtonText: "去注册",
        type: "warning",
      })
        .then(() => {
          this.$router.push({ path: "/login" });
        })
        .catch(() => {
          this.$router.push({ path: "/register" });
        });
    },
    logout() {
      cookie.set("userInfo", "");
      cookie.set("token", "");
    },
    getQueryString(name) {
      var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
      var r = window.location.search.substr(1).match(reg);
      if (r != null) {
        return unescape(r[2]);
      }
      return null;
    },
    timestampToTime(timestamp) {
        var date = new Date(timestamp * 1000);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
        var Y = date.getFullYear() + '-';
        var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1):date.getMonth()+1) + '-';
        var D = (date.getDate()< 10 ? '0'+date.getDate():date.getDate())+ ' ';
        var h = (date.getHours() < 10 ? '0'+date.getHours():date.getHours())+ ':';
        var m = (date.getMinutes() < 10 ? '0'+date.getMinutes():date.getMinutes()) + ':';
        var s = date.getSeconds() < 10 ? '0'+date.getSeconds():date.getSeconds();
        return Y+M+D+h+m+s;
    },


  },
  mounted() {
    var orderId = this.getQueryString("orderId");
    var productId = this.getQueryString("productId");
    orderApi.queryProductById(orderId, productId).then((response) => {
      if (response.data.code == 200) {
        this.productInfo = response.data.data.data;
      } else {
        this.$message.error("请求出错");
      }
    });
  },
};
</script>